<?php
/**
 * Generic login/register and forgotten password form logic.
 * 
 * @package disputeo
 * @version 1.0
 * @author jimmy.dixon
 */

class Application_Form_Entry extends Disputeo_Form
{
    /**
     * @var string 
     */
    protected $_passwordTooShort = 'Password must be at least 6 characters.';
    
    /**
     * @var string 
     */
    protected $_passwordTooLong = 'Password cannot be more than 20 characters.';
    
    /**
     * @var string 
     */
    protected $_passwordEmpty = 'Password cannot be left blank.';
    
    /**
     * @var string 
     */
    protected $_usernameTooShort = 'User Name must be at least 6 characters.';
    
    /**
     * @var string 
     */
    protected $_usernameTooLong = 'User Name cannot be more than 20 characters.';
    
    /**
     * @var string 
     */
    protected $_usernameEmpty = 'User Name cannot be left blank.';
    
    /**
     * @var string 
     */
    protected $_displayGroup = array();
    
    /**
     * Add password element to form
     */
    protected function _addPasswordElement()
    {
        $password = new Zend_Form_Element_Password('password');
        $password->setLabel('Password')
                ->addValidator('NotEmpty', false, array('messages' =>
                    array('isEmpty' => $this->_passwordEmpty)))
                ->addValidator('stringLength', false, array(6, 20, 'messages' =>
                    array(Zend_Validate_StringLength::TOO_SHORT => $this->_passwordTooShort,
                        Zend_Validate_StringLength::TOO_LONG => $this->_passwordTooLong)))
                ->setRequired(true)
                ->removeDecorator('Errors')
                ->setAttrib('renderPassword', true);
        $this->addElement($password);
    }

    /**
     * Add username element to form
     */
    protected function _addUserNameElement()
    {
        $user = new Zend_Form_Element_Text('username');
        $user->setLabel('User Name')
                ->addValidator('NotEmpty', false, array('messages' =>
                    array('isEmpty' => $this->_usernameEmpty)))
                ->addValidator('stringLength', false, array(6, 20, 'messages' =>
                    array(Zend_Validate_StringLength::TOO_SHORT => $this->_usernameTooShort,
                        Zend_Validate_StringLength::TOO_LONG => $this->_usernameTooLong)))
                ->setRequired(true)
                ->removeDecorator('Errors');
        $this->addElement($user);
    }

    /**
     * Add submit element to form
     */
    protected function _addSubmitElement($label = 'Submit')
    {
        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel($label);
        $submit->setDecorators(array(
            array('ViewHelper'),
            array('Errors'),
            array('Description'),
            array('HtmlTag', array('tag' => 'p', 'class' => 'submit'))
        ));
        $this->addElement($submit);
    }

    /**
     * Set fieldset
     */
    protected function _addToDisplayGroup($element)
    {
        $this->_displayGroup[] = $element;
    }

    /**
     * Add fieldset to form
     */
    protected function _addDisplayGroup($group, $legend)
    {
        $legend = array('legend' => $legend);
        $this->addDisplayGroup($this->_displayGroup, $group, $legend);
        $displayGroup = $this->getDisplayGroup($group);
        $displayGroup->removeDecorator('DtDdWrapper');
    }
    
}